package com.yuqian.JavaSe.snio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

public class SServerSocketChannel {
	public static void main(String[] args) throws IOException {
		while(true) {
			ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
            serverSocketChannel.configureBlocking(true);
            serverSocketChannel.bind(new InetSocketAddress(90));

            System.out.println("[server]accepting...");

            SocketChannel client = serverSocketChannel.accept();

            ByteBuffer dst = ByteBuffer.allocate(1024);
            client.read(dst);

            String result = new String(dst.array(), "UTF-8");

            System.out.println("->" + result);
            serverSocketChannel.close();
		}
	}
}
